angular.module('imsApp').controller('promotionStatisticsController', ['$scope', '$rootScope', '$state', 'PromotionGroupManager', function ($scope, $rootScope, $state, PromotionGroupManager) {
    $scope.search = {
        groupId: $state.params.groupId,
        timeType: $state.params.timeType || 'day',
        pageNo: $state.params.pageNo || 1,
        pageSize: $state.params.pageSize || 10
    };
    $scope.paginationDetail = {
        currentPage: $scope.search.pageNo,
        itemsPerPage: $scope.search.pageSize,
        pagesLength: 9,
        search: 0,
        onChange: function () {
            $scope.search.pageNo = this.currentPage;
            $scope.search.pageSize = this.itemsPerPage;
            $state.go($state.current.name, {
                groupId: $scope.search.groupId,
                pageNo: $scope.search.pageNo,
                pageSize: $scope.search.pageSize,
                timeType: $scope.search.timeType
            }, {inherit: false})
        }
    };


    PromotionGroupManager.promotionGroupStatistics([$scope.search.groupId, $scope.search.pageNo, $scope.search.pageSize], {timeType: $scope.search.timeType}).then(function (result) {
        $scope.statisticsList = result.data;
        if ($scope.statisticsList.c == "s") {
            $scope.lists = $scope.statisticsList.pageList;
            $scope.total = $scope.statisticsList.countStat;
            $scope.paginationDetail.totalItems =$scope.statisticsList.total;
            $scope.title = $scope.statisticsList.title;
            $scope.uTime = $scope.statisticsList.uTime;
        }

    })

    $scope.timeTypeChange = function (type) {
        console.log(type)
        $state.go($state.current.name, {
            groupId: $scope.search.groupId,
            pageNo: 1,
            pageSize: 10,
            timeType: type
        }, {inherit: false})
    }


}])

